function [valor,valor_area]=ganchos_arpones(upperbaseline,downbaseline,xbin,grosor)
[m,n]=size(xbin);
[f,c]=find(xbin([upperbaseline:downbaseline],:)==0);
cc=c(1);
[f1,c1]=find(xbin([upperbaseline:downbaseline],cc)==0);
while length(f1)<=grosor
    clear f1 c1
    cc=cc+1;
    [f1,c1]=find(xbin([upperbaseline:downbaseline],cc)==0);
end
if (cc-c(1))==1
    valor1=0;
    valor_area1=0;
else
    valor1=cc-c(1);
    xx=ones(m,cc);
    ww=zeros(m,cc);
    f1=f1+(upperbaseline-1);
    f3=max(f1);
    xx([f1(1):f1(end)],cc)=0;
    fin_f=min(f1);
    fin_c=cc;
    cc=cc-1;    
    if isempty(find(xbin([f3-1:f3+1],cc)==0))==0
        while (cc>=1)&&(isempty(find(xbin([f3-1:f3+1],cc)==0))==0)
            [f2,c2]=find(xbin([f3-1:f3+1],cc)==0);
            f2=f2+(f3-2);
            f3=max(f2);
            xx([f2(1):f2(end)],cc)=0;
            cc=cc-1;
        end
        cc=cc+1;
        f3=min(f2);
        if xbin((f3-1),cc)==0
            while xbin((f3-1),cc)==0
                xx(f3-1,cc)=0;
                f3=f3-1;
            end 
            while (isempty(find(xbin([f3-1:f3+1],cc+1)==0))==0)&&(cc<=fin_c)
                [f2,c2]=find(xbin([f3-1:f3+1],cc+1)==0);
                f2=f2+(f3-2);
                f3=min(f2);
                xx([f2(1):f2(end)],cc)=0;
                cc=cc+1;
            end
        end
    end
ini_f=f3;
ini_c=cc;
for ccc=ini_c+1:fin_c-1
    fff=(floor(((ccc-ini_c)*((fin_f-ini_f)/(fin_c-ini_c)))+ini_f));
    xx(fff,ccc)=0;   
end
ww(find(xx==0))=1;
SE=strel('square',3);
ww=imclose(ww,SE);
clear fff ccc
[fff,ccc]=find(ww==1);
valor_area1=length(fff);
%figure;
%imshow(xx)
end


%%%%%%
clear xx ww
cc=c(end);
[f1,c1]=find(xbin([upperbaseline:downbaseline],cc)==0);
while length(f1)<=grosor
    clear f1 c1 f2 c2 f3
    cc=cc-1;
    [f1,c1]=find(xbin([upperbaseline:downbaseline],cc)==0);
end
if (c(end)-cc)==1
    valor2=0;
else
    valor2=c(end)-cc;
    xx=ones(m,n);
    ww=zeros(m,n);
    f1=f1+(upperbaseline-1);
    f3=min(f1);
    xx([f1(1):f1(end)],cc)=0;
    ini_f=max(f1);
    ini_c=cc;
    cc=cc+1;
    if isempty(find(xbin([f3-1:f3+1],cc)==0))==0
        while (cc<=n)&&(isempty(find(xbin([f3-1:f3+1],cc)==0))==0)
            [f2,c2]=find(xbin([f3-1:f3+1],cc)==0);
            f2=f2+(f3-2);
            f3=max(f2);
            xx([f2(1):f2(end)],cc)=0;
            cc=cc+1;
        end
        cc=cc-1;
        f3=min(f2);
        if xbin((f3-1),cc)==0
            while xbin((f3-1),cc)==0
                xx(f3-1,cc)=0;
                f3=f3-1;
            end 
            while (isempty(find(xbin([f3-1:f3+1],cc-1)==0))==0)&&(cc<=ini_c)
                [f2,c2]=find(xbin([f3-1:f3+1],cc-1)==0);
                f2=f2+(f3-2);
                f3=max(f2);
                xx([f2(1):f2(end)],cc)=0;
                cc=cc-1;
            end
        end
    end
fin_f=f3;
fin_c=cc;
for ccc=ini_c+1:fin_c-1
    fff=(ceil(((ccc-ini_c)*((fin_f-ini_f)/(fin_c-ini_c)))+ini_f));
    xx(fff,ccc)=0;   
end
ww(find(xx==0))=1;
SE=strel('square',3);
ww=imclose(ww,SE);
clear fff ccc
[fff,ccc]=find(ww==1);
valor_area2=length(fff);
%figure;
%imshow(xx)
end

    
if (valor1>0)&&(valor2>0)
    valor=(valor1+valor2)/2;
    valor_area=(valor_area1+valor_area2)/2;
elseif (valor1==0)&&(valor2>0)
    valor=valor2;
    valor_area=valor_area2;
else
    valor=valor1;
    valor_area=valor_area1;
end